module STM4_GLB_REGS(
   input                         MPI_RESET,

   input                         MPI_CLK,
   input[7:0]                    MPI_ADDR,
   input                         MPI_CS,
   input                         MPI_WE,
   input[15:0]                   MPI_WD,
   output reg[15:0]              MPI_RD,

   output reg[3:0]               GLBCF_LINF_MODE
    ) ;

//  ++++++++++++++++++ Adrress map table    ++++++++++++++++++ //
//  0x0000            Chip ID
//  0x0001            Chip Release Version
//  0x0002            Chip Debug Version, reserved for test
//  0x0008            Scratch Registers for write/read test
//  0x0010            the mode configuartion for line interface stm-1/stm-4

reg[15:0]                               GREG_SCRATCH_PAD;

always @( posedge MPI_RESET or posedge MPI_CLK ) begin
   if ( MPI_RESET==1'b1 ) begin
      GREG_SCRATCH_PAD[15:0]                             <= 16'd0;
      GLBCF_LINF_MODE[3:0]                               <= 4'd0;
   end
   else if ( MPI_WE==1'b1 && MPI_CS==1'b1 ) begin
      case ( MPI_ADDR[7:0] )
      8'h08: GREG_SCRATCH_PAD[15:0]                      <= MPI_WD[15:0];
      8'h10: GLBCF_LINF_MODE[3:0]                        <= MPI_WD[3:0];
      default: ;
      endcase
   end
end

always @( posedge MPI_RESET or posedge MPI_CLK ) begin
   if ( MPI_RESET==1'b1 )
      MPI_RD[15:0]                                       <= 16'd0;
   else begin
      if ( MPI_CS==1'b1 ) begin
         case ( MPI_ADDR[7:0] )
         8'h00: MPI_RD[15:0]                             <= 16'h1000;
         8'h01: MPI_RD[15:0]                             <= 16'h0010;
         8'h02: MPI_RD[15:0]                             <= 16'h0001;
         8'h08: MPI_RD[15:0]                             <= GREG_SCRATCH_PAD[15:0];
         8'h10: MPI_RD[15:0]                             <= {12'd0, GLBCF_LINF_MODE[3:0]};
         default: MPI_RD[15:0]                           <= 16'd0;
         endcase
      end
      else begin
         MPI_RD[15:0]                                    <= 16'd0;
      end
   end
end

endmodule
